package com.example.beat_x3.Fragments;

import android.annotation.SuppressLint;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.example.beat_x3.MainActivity;
import com.example.beat_x3.R;

import Entity.Inf;

public class MyFragment extends Fragment{
    @SuppressLint("StaticFieldLeak")
    public void changeFragment(Fragment fragment){
        MainActivity mainActivity=(MainActivity)getActivity();
        assert mainActivity != null;
        FragmentTransaction transaction= mainActivity.getSupportFragmentManager().beginTransaction();
        if (Inf.current_fragment != fragment) {
            if (!fragment.isAdded()) {
                transaction.hide(Inf.current_fragment).add(R.id.fragmentContainerView, fragment).commit();
            } else {
                transaction.hide(Inf.current_fragment).show(fragment).commit();
            }
            Inf.current_fragment = fragment;
        }
    }
}
